from sklearn.linear_model import Ridge
import matplotlib.pyplot as plt
import h5py
import numpy as np
from y import Y

model = Ridge(alpha=0.05)

f = h5py.File('out/feature/train.h5', 'r')
x = f['x'][...]
y = f['y'][...][:, Y]
model.fit(x, y)

f = h5py.File('out/feature/test.h5', 'r')
x = f['x'][...]
y = f['y'][...][:, Y]
r2 = model.score(x, y)
y_pred = model.predict(x)
loss = 0
l2 = ((y-y_pred)**2).sum() / len(y)
print('r2', r2)
print('l2', l2)

plt.figure()
plt.scatter(np.sort(y_pred), np.sort(y), s=0.1)
plt.xlabel('y_pred')
plt.ylabel('y_true')
plt.savefig('sklearn_qq.png')

